/**
 * Created by xinhuang on 15/6/14.
 */
(function (angular) {
  'use strict';

  angular.module('directives.customActivity', [
    'directives.customActivity.realtime'
  ])
    .directive('pageGenerate', pageGenerate)
    .directive('previewEdit', previewEdit);

  function pageGenerate($compile, activityManager, previewEditor) {
    return {
      restrict: 'A',
      link: postLink
    };

    function postLink(scope, element) {
      activityManager.getSavedConfig(scope.activityId, function () {
        var dom = $compile(activityManager.configure.layout)(scope);
        element.html();
        element.append(dom);
        previewEditor.pageGenarator(element);
      });
    }
  }

  function previewEdit($compile, previewEditor, previewEdited) {
    return {
      restrict: 'A',
      link: postLink
    };

    function postLink(scope, element) {
      var dom = $compile(scope.activityManager.configure.layout)(scope);
      element.html();
      element.append(dom);
      previewEditor.pageGenarator(element);
      previewEditor.addDragEvent();
    }
  }
})(angular);